package com.asset.salesforce.view;

import java.awt.Color;
import java.util.List;

import com.asset.salesforce.domain.InvoiceService;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;

public class InvoiceServiceTable {
	
	public static Font normalFont = new Font(FontFactory.getFont(String.valueOf(Font.TIMES_ROMAN),BaseFont.TIMES_ROMAN,9,Font.NORMAL));
	
	public PdfPTable pdfPTable(List<InvoiceService>invoiceServices)throws Exception{

		PdfPTable table1 = new PdfPTable(8);
	      PdfPCell cell1 = new PdfPCell (new Paragraph ("Service Invoice",new Font(FontFactory.getFont(String.valueOf(Font.TIMES_ROMAN),BaseFont.TIMES_ROMAN,11,Font.BOLD))));
	      cell1.setColspan (8);
	      cell1.setHorizontalAlignment (Element.ALIGN_CENTER);
	      cell1.setBackgroundColor (new Color (128, 200, 128));
	      //cell.setPadding (9.0f);
	      cell1.setFixedHeight(18);
	      //cell.setBorderWidth(20);
	      table1.addCell (cell1);
	      
	      cell1 = new PdfPCell(new Paragraph("Name",normalFont));
	      cell1.setHorizontalAlignment (Element.ALIGN_CENTER);
	      cell1.setBackgroundColor (new Color (255, 200, 0));
	      //cell.setPadding (9.0f);
	      cell1.setFixedHeight(18);
	      table1.addCell (cell1);
	      
	      cell1 = new PdfPCell(new Paragraph("Info",normalFont));
	      cell1.setHorizontalAlignment (Element.ALIGN_CENTER);
	      cell1.setBackgroundColor (new Color (255, 200, 0));
	      //cell.setPadding (9.0f);
	      cell1.setFixedHeight(18);
	      table1.addCell(cell1);
	      
	      cell1 = new PdfPCell(new Paragraph("Discount",normalFont));
	      cell1.setHorizontalAlignment (Element.ALIGN_CENTER);
	      cell1.setBackgroundColor (new Color (255, 200, 0));
	      //cell.setPadding (9.0f);
	      cell1.setFixedHeight(18);
	      table1.addCell (cell1);
	      
	      cell1 = new PdfPCell(new Paragraph("Cost",normalFont));
	      cell1.setHorizontalAlignment (Element.ALIGN_CENTER);
	      cell1.setBackgroundColor (new Color (255, 200, 0));
	      //cell.setPadding (9.0f);
	      cell1.setFixedHeight(18);
	      table1.addCell (cell1);
	      
	      cell1 = new PdfPCell(new Paragraph("Hours",normalFont));
	      cell1.setHorizontalAlignment (Element.ALIGN_CENTER);
	      cell1.setBackgroundColor (new Color (255, 200, 0));
	      //cell.setPadding (9.0f);
	      cell1.setFixedHeight(18);
	      table1.addCell (cell1);
	      
	      cell1 = new PdfPCell(new Paragraph("Tax1",normalFont));
	      cell1.setHorizontalAlignment (Element.ALIGN_CENTER);
	      cell1.setBackgroundColor (new Color (255, 200, 0));
	      //cell.setPadding (9.0f);
	      cell1.setFixedHeight(18);
	      table1.addCell (cell1);
	      
	      cell1 = new PdfPCell(new Paragraph("Tax2",normalFont));
	      cell1.setHorizontalAlignment (Element.ALIGN_CENTER);
	      cell1.setBackgroundColor (new Color (255, 200, 0));
	      //cell.setPadding (9.0f);
	      cell1.setFixedHeight(18);
	      table1.addCell (cell1);
	      
	      cell1 = new PdfPCell(new Paragraph("Line Total",normalFont));
	      cell1.setHorizontalAlignment (Element.ALIGN_CENTER);
	      cell1.setBackgroundColor (new Color (255, 200, 0));
	      //cell.setPadding (10.0f);
	      cell1.setFixedHeight(18);
	      table1.addCell (cell1);
	      table1.setWidthPercentage(100);
				  if(invoiceServices.size()>0){
						for (InvoiceService invoiceService : invoiceServices) {
							table1.addCell(new Paragraph(invoiceService.getName(),normalFont));
							table1.addCell(new Paragraph(invoiceService.getInfo(),normalFont));
							table1.addCell(new Paragraph(invoiceService.getDiscount(),normalFont));
							table1.addCell(new Paragraph(invoiceService.getCostPerHour(),normalFont));
							table1.addCell(new Paragraph(invoiceService.getHours(),normalFont));
							if(invoiceService.getTaxOne()!=null){
								table1.addCell(new Paragraph(invoiceService.getTaxOne().toString(),normalFont));
							}
							else{
								table1.addCell(new Paragraph("",normalFont));
							}
							
							if(invoiceService.getTaxTwo()!=null){
								table1.addCell(new Paragraph(invoiceService.getTaxTwo().toString(),normalFont));
							}
							else 
							{
								table1.addCell(new Paragraph("",normalFont));
							}
							if(invoiceService.getTotalCost()!=null){
								table1.addCell(new Paragraph(invoiceService.getTotalCost(),normalFont));
							}
							else{
								table1.addCell(new Paragraph("",normalFont));
							}
//							table1.addCell(new Paragraph(invoiceService.getTaxOne().toString(),normalFont));
//							table1.addCell(new Paragraph(invoiceService.getTaxTwo().toString(),normalFont));
//							table1.addCell(new Paragraph(invoiceService.getTotalCost().toString(),normalFont));

						}
					}
		  //    }
			  //table1.setCellsFitPage(true);
				  table1.setSpacingBefore(5f);
		    	  table1.setSpacingAfter(10f);
		    	  
		    	  return table1;
	}
}
